<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    //1.验证由26个字母组成的字符串
    let str = "ab_c21"
    let reg = /^[a-zA-Z]+$/
    console.log(reg.test(str)) //false
    //2.验证由字母和数字_组成的字符串
    reg = /^\w+$/
    console.log(reg.test(str)) //ture
    //3.验证汉字
    reg = /^[u4e00-\u9fa5a-z]+$/
    let st = "验证汉字a"
    console.log(reg.test(st)) //ture
    //4.验证手机号码
    reg = /^1[356789]\d{9}$/
    let tel = '13866130652'
    console.log(reg.test(tel)) //ture
    //5验证邮箱
    reg = /^[a-zA-Z0-9]+@[a-zA-Z0-9]{2,}(\.com|\.cn|\.com\.cn|\.org|\.net|\.edu)$/
    let email = "95243@qq.com"
    console.log(reg.test(email)) //ture
    //6获得字符串中所有数字、汉字、字母
    let name = "尼古拉斯-catch-1世"
    console.log(name.match(/[\u4e00-\u9fa5]/g).join(''))
    console.log(name.match(/[a-zA-Z]/g).join(''))
    console.log(name.match(/\d/g).join(''))
    //7.使用正则去除所有空格
    let add = " a b c _ 1 "
    //add = add.replace(/\s/g, "")
    // console.log(add)
    //8.首尾去空格
    add = add.replace(/(^\s+)|(\s+$)/g, "")
    console.log(add)
    let nickName = "空格"
    let reg1 = /(^[\u4e00-\u9fa5]{2,}$)|(^[a-zA-Z]{3,}$)/
    console.log(reg1.test(nickName))
</script>

</html>